using System;
using System.ComponentModel;
using System.Linq.Expressions;
using KT.Expressions;
using KT.Mvvm;

namespace KT.Mvvm
{
    public static class PublicNotifyPropertyChangedImplementation
    {
        public static void NotifyPropertyChanged(this IPublicNotifyPropertyChanged obj, params Expression<Func<object>>[] expressions)
        {
            foreach (var expr in expressions)
                obj.NotifyPropertyChanged(ExpressionUtils.PropertyToString(expr));
        }        
    }

    public class MvvmBase: INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        protected void NotifyPropertyChanged(string propertyName)
        {
            PropertyChanged.Raise(propertyName, this);
        }

        protected void NotifyPropertyChanged(params Expression<Func<object>>[] expressions)
        {
            foreach (var expr in expressions)
                NotifyPropertyChanged(ExpressionUtils.PropertyToString(expr));
        }
    }
}